//
//  GMFUpperToolbarView.m
//  SplunkMobile
//
//  Created by lijunying on 1/28/2016.
//  Copyright © 2016 Gome. All rights reserved.
//

#import "GMFUpperToolbarView.h"

@interface GMFUpperToolbarView()

@property (nonatomic, weak) UIButton *btnClose;
@property (nonatomic, weak) UIButton *btnSend;
/// 记录有几个按钮
@property (nonatomic, assign) int cintButtonCount;

@property (nonatomic, weak) UIView *viewSeperateLine;

@end


@implementation GMFUpperToolbarView

- (id)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        self.backgroundColor = GMKColor(51, 51, 51);
        self.alpha = 0.95;
        
        /// 关闭
        UIButton *btnClose = [[UIButton alloc] init];
//        [btnClose setImage:[UIImage imageNamed:@"btn_close"] forState:UIControlStateNormal];
        [btnClose setTitle:@"退出批注" forState:UIControlStateNormal];
//        btnClose.backgroundColor = [UIColor redColor];
//        btnClose.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        btnClose.titleLabel.font = [UIFont systemFontOfSize:14];
        
        btnClose.tag = 1000;
        [btnClose addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btnClose];
        self.btnClose = btnClose;
        _cintButtonCount++;
        
//        /// 缩放
//        UIButton *btnZoom = [[UIButton alloc] init];
//        [btnZoom setImage:[UIImage imageNamed:@"btn_zoomout"] forState:UIControlStateNormal];
//        btnZoom.tag = 1001;
//        [btnZoom addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
//        [self addSubview:btnZoom];
//        self.btnZoom = btnZoom;
//        _cintButtonCount++;
        
//        /// 画图
//        UIButton *btnDraw = [[UIButton alloc] init];
//        [btnDraw setImage:[UIImage imageNamed:@"btn_pen"] forState:UIControlStateNormal];
//        btnDraw.tag = 1002;
//        [btnDraw addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
//        [self addSubview:btnDraw];
//        self.btnDraw = btnDraw;
//        _cintButtonCount++;
//        
//        /// 调色板
//        UIButton *btnPalette = [[UIButton alloc] init];
//        [btnPalette setImage:[UIImage imageNamed:@"btn_palette"] forState:UIControlStateNormal];
//        btnPalette.tag = 1003;
//        [btnPalette addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
//        [self addSubview:btnPalette];
//        self.btnPalette = btnPalette;
//        _cintButtonCount++;
        
        /// 后退
        UIButton *btnUndo = [[UIButton alloc] init];
//        [btnUndo setImage:[UIImage imageNamed:@"btn_undo"] forState:UIControlStateNormal];
        [btnUndo setTitle:@"撤销" forState:UIControlStateNormal];
//        btnUndo.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
//        btnUndo.backgroundColor = [UIColor redColor];
        btnUndo.titleLabel.font = [UIFont systemFontOfSize:14];
        [btnUndo setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        btnUndo.tag = 1004;
        [btnUndo addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btnUndo];
        self.btnUndo = btnUndo;
        _cintButtonCount++;
        
        /// 前进
        UIButton *btnRedo = [[UIButton alloc] init];
//        [btnRedo setImage:[UIImage imageNamed:@"btn_redo"] forState:UIControlStateNormal];
        [btnRedo setTitle:@"重做" forState:UIControlStateNormal];
//        btnRedo.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
//        btnRedo.backgroundColor = [UIColor redColor];
        [btnRedo setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        btnRedo.titleLabel.font = [UIFont systemFontOfSize:14];
        btnRedo.tag = 1005;
        [btnRedo addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btnRedo];
        self.btnRedo = btnRedo;
        _cintButtonCount++;
        
        /// 清除
        UIButton *btnClear = [[UIButton alloc] init];
//        [btnClear setImage:[UIImage imageNamed:@"btn_clear"] forState:UIControlStateNormal];
        [btnClear setTitle:@"清除" forState:UIControlStateNormal];
//        btnClear.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
//        btnClear.backgroundColor = [UIColor redColor];
        btnClear.titleLabel.font = [UIFont systemFontOfSize:14];
        btnClear.tag = 1006;
        [btnClear addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btnClear];
        self.btnClear = btnClear;
        _cintButtonCount++;
        
//        /// 编辑文本
//        UIButton *btnAddText = [[UIButton alloc] init];
//        [btnAddText setImage:[UIImage imageNamed:@"btn_text_add"] forState:UIControlStateNormal];
//        btnAddText.tag = 1007;
//        [btnAddText addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
//        [self addSubview:btnAddText];
//        self.btnAddText = btnAddText;
//        _cintButtonCount++;
        
        /// 发送
        UIButton *btnSend = [[UIButton alloc] init];
//        [btnSend setImage:[UIImage imageNamed:@"btn_share"] forState:UIControlStateNormal];
        [btnSend setTitle:@"发送" forState:UIControlStateNormal];
//        btnSend.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
//        btnSend.backgroundColor = [UIColor redColor];
        btnSend.titleLabel.font = [UIFont systemFontOfSize:14];
        btnSend.tag = 1008;
        [btnSend addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btnSend];
        self.btnSend = btnSend;
        _cintButtonCount++;
        
//        UIView *viewSeperateLine = [[UIView alloc] init];
//        viewSeperateLine.backgroundColor = GMKColor(210, 210, 210);
//        [self addSubview:viewSeperateLine];
//        self.viewSeperateLine = viewSeperateLine;
    }
    
    return self;
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    
    CGFloat fltPadding = 15;
    CGFloat fltPaddingBetweenButtons = (screenW - fltPadding * 2 - (fltButtonWidth + 25) * _cintButtonCount) / (_cintButtonCount - 1);
    
    [_btnClose      setFrame:CGRectMake((fltButtonWidth + 25) * 0 + fltPadding + fltPaddingBetweenButtons * 0 + 4, 0, fltButtonWidth + 25, fltButtonWidth - 8)];
    [_btnUndo       setFrame:CGRectMake((fltButtonWidth + 25) * 1 + fltPadding + fltPaddingBetweenButtons * 1 + 4, 0, fltButtonWidth + 25, fltButtonWidth - 8)];
    [_btnRedo       setFrame:CGRectMake((fltButtonWidth + 25) * 2 + fltPadding + fltPaddingBetweenButtons * 2 + 4, 0, fltButtonWidth + 25, fltButtonWidth - 8)];
    [_btnClear      setFrame:CGRectMake((fltButtonWidth + 25) * 3 + fltPadding + fltPaddingBetweenButtons * 3 + 4, 0, fltButtonWidth + 25, fltButtonWidth - 8)];
    [_btnSend       setFrame:CGRectMake((fltButtonWidth + 25) * 4 + fltPadding + fltPaddingBetweenButtons * 4 + 4, 0, fltButtonWidth + 25, fltButtonWidth - 8)];
}


- (void)buttonClick:(UIButton *)button
{
    NSString *string = [NSString stringWithFormat:@"%ld", (long)button.tag];
    
    if ([self.delegate respondsToSelector:@selector(upperToolbarView: buttonTagString:)])
    {
        [self.delegate upperToolbarView:self buttonTagString:string];
    }
}


@end




